def getNodeValue(node):
    if node != None:
        printList = [ '[',node.start,', ',node.end,']']
        if hasattr(node,'max'):
            printList.insert(-1,', max=' + str(node.max))

        return ''.join(str(x) for x in printList)

    else:
        return 'null'


def printSegmentTree(tree):
    valueListMap = getSegmentTreeValueMap(tree)
    valueList = valueListMap.values()
    values = []
    for l in valueList:
        values.extend(l)
    print tuple(values)

def getSegmentTreeValueMap(tree):
    valueListMap = {}
    level = 0
    def walk(node, outList, level):
        if not valueListMap.has_key(level):
            valueListMap[level] = []
        nodeValue = getNodeValue(node)
        valueListMap[level].append(nodeValue)

        nextLevel = level+1
        if not valueListMap.has_key(nextLevel):
                valueListMap[nextLevel] = []

        if node.left == None and node.right == None:
            return
            
        if node.left == None:
            valueListMap[nextLevel].append('#')
        else:
            walk(node.left, valueListMap, nextLevel)
            
        if node.right == None:
            valueListMap[nextLevel].append('#')
        else:
            walk(node.right, valueListMap, nextLevel)
            
    walk(tree, valueListMap, level)
    
    return valueListMap
    
    

def printListNode(node):
    import sys
    sys.stdout.write(str(node.val)+'->')
    next = node.next;
    if next:
        printListNode(next)
    else:
        print 'None'


def listToListNode(list, ListNode):
    head = point = ListNode(list[0])
    for val in list[1:]:
        listNode = ListNode(val)
        point.next = listNode
        point = listNode

    return head
